package leetcode.Y2024M6.review;

import org.junit.Test;

public class S55 {
    public boolean canJump(int[] nums) {
        int distance = 0;
        int i = 0;
        for (; i < nums.length; i++) {
            if (i > distance) return false;
            distance = Math.max(distance, nums[i] + i);

        }


        return true;
    }

    @Test
    public void test() {
        int[] nums = {2, 3, 1, 1, 4};
        System.out.println(canJump(nums));
    }

    @Test
    public void test1() {
        int[] nums = {2, 0, 0};
        System.out.println(canJump(nums));
    }

    @Test
    public void test2() {
        int[] nums = {0};
        System.out.println(canJump(nums));
    }

    @Test
    public void test3() {
        int[] nums = {3,2,1,0,4};
        System.out.println(canJump(nums));
    }
}
